import React, { useCallback, useEffect, useState } from 'react';
// import { RequestApi } from '../../../net/common/API';
import emitter from '../../../utils/Notification';
import { Button } from 'antd';
import UserManagement from '../../../components/UserManagement';

export default () => {
  const [isModalVisible, setIsModalVisible] = useState(false);

  useEffect(() => {
    // let apiObj = {
    //   url: '/luggage/pkg/getPkgAccidentDetail',
    //   method: 'get',
    //   params: {
    //     accidentId: 1,
    //   },
    // };
    // new RequestApi().getRequest(apiObj).then((res) => {
    //   console.log(res, '--netDemoRes--');
    // });
    emitter.addObserver('1', (obj) => {
      console.log('aaaa', obj);
    });
    emitter.addObserver('2', (obj) => {
      console.log('bbbbb', obj);
    });
  }, []);

  const openModal = useCallback(() => {
    setIsModalVisible(true);
  }, []);
  const handleSubmit = useCallback((arr) => {
    console.log(arr, 'handleSubmit');
    setIsModalVisible(false);
  }, []);
  const handleCancel = useCallback(() => {
    setIsModalVisible(false);
  }, []);

  return (
    <>
      <Button
        onClick={() => {
          emitter.postNotification('1', '1111111');
          emitter.postNotification('2', '2222222');
        }}
      >
        post
      </Button>
      <Button
        onClick={() => {
          // emitter.removeObserverAll()
          emitter.removeObserver('1');
          emitter.removeObserver('2');
        }}
      >
        remove
      </Button>
      <Button onClick={openModal}>打开弹窗</Button>
      <UserManagement
        isModalVisible={isModalVisible}
        handleSubmit={handleSubmit}
        handleCancel={handleCancel}
        type={2}
      ></UserManagement>
    </>
  );
};
